package com.example.demorabbitmq.test;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

import static com.example.demorabbitmq.config.RabbitConfig.TEST_QUEUE_NAME_1;
import static com.example.demorabbitmq.config.RabbitConfig.TEST_QUEUE_NAME_2;


/**
 * @author wangbin
 */
@RestController
public class ProducerController {
    @Resource
    private AmqpTemplate amqpTemplate;

    @GetMapping("/send1")
    public void send1() {
        amqpTemplate.convertAndSend(TEST_QUEUE_NAME_1 + ".exchange", TEST_QUEUE_NAME_1, "测试消息1");
    }

    @GetMapping("/send2")
    public void send2() {
        Map<String, Object> message = new HashMap<>();
        message.put("msg", "测试消息2");
        amqpTemplate.convertAndSend(TEST_QUEUE_NAME_2 + ".exchange", TEST_QUEUE_NAME_2, message);
    }

}